package Stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: cyy
 **/
public class demo1 {
    public static void main(String[] args) {
        /*List<Integer> numbers = Arrays.asList(2, 3, 4, 5);
        List<Integer> result =
                numbers.stream()
                        .peek(x -> System.out.println("from stream: " + x))
                        .map(x -> x + 17)
                        .peek(x -> System.out.println("after map: " + x))
                        .filter(x -> x % 2 == 0)
                        .peek(x -> System.out.println("after filter: " + x))
                        .limit(2)
                        .peek(x -> System.out.println("after limit: " + x))
                        .collect(Collectors.toList());*/

            List<Integer> integers = Arrays.asList(1, 2, 3, 6, 8);
            //求list中的和，以0为基数
            Integer reduce = integers.stream().reduce(0, (a, b) -> a + b);
            //Integer的静态方法
            int sum = integers.stream().reduce(0, Integer::sum);
            System.out.println("reduce = " + reduce +"==========sum:" + sum);


    }
}
